$(function(){
    var $register_username;
    var $register_password;
    var $register_password_confirm;
    var $reg1 = /^[A-Za-z0-9]{3,11}$/;//用户名要求是3~11的位的字母或者数字
    var $reg2 = /^[A-Za-z0-9]{6,11}$/;//密码要求是6~11的位的字母或者数字

    //对于用户是否登录的检测请求
    $('#login').on('click',function(){
    	var $username=$("#username").val();
    	var $password=$("#password").val();
    	var $securityCode=$("#securityCode").val();
    	$.ajax({
            "url": '/forum/user_login.action',
            "type": 'POST',
            "dataType": 'json',
            "data": {"user.username":$username,"user.userPass":$password,"loginSecurityCode":$securityCode},
            "contentType":"application/x-www-form-urlencoded; charset=UTF-8",
            "success":function(data){
//                var data = $.parseJSON(data);
                alert(data);
                if(data=="login_successful"){
                	alert("login_successful");
                    console.log(data[1].username); 
                    $('.hidden').css({
                        "display":"none"
                    });
                    $('.onhidden').css({
                        "display":"block"
                    });//改变登录样式
                }
            },
            "error":function(){
                console.log("网络错误！");
            }
        });
    })

    //退出登录事件
    $(document).on('click',".logout", function(event) {
        event.preventDefault();
        $.ajax({
            url: '.....action',
            type: 'GET',
            dataType: 'json',
            data: {},
            success:function(){
                location.reload();
            }
        })
    });

    //登录事件
    $('#box_up').on('click',function() {
        var $username = encodeURI($("#username").val());
        var $password = $("#password").val();
        $.ajax({
            "type":"POST",
            "url":".....action",
            "dataType":"json",
            "data":{"username":$username,"password":$password},
            "contentType":"application/x-www-form-urlencoded; charset=UTF-8",
            "success":function(data){
                var data = $.parseJSON(data.content);
                if(data[0].status=="1"){
                    $('#box_up').before('<p class="login-success">登陆成功！</p>');
                    setTimeout(function(){
                        location.reload();
                    },500)
                }
                else{
                    $('#box_up').before('<p class="login-error">用户名或者密码错误！</p>');
                }
            },
            "error":function(){
                alert("网络不畅，请稍后再试！");
            }
        })
    });
})

